%function stackVecFiles
%
% Julio Barros

clear

disp('Enter the path where the files are. Dont forget to put the correct "/"(slash) ')
folData = input(': ','s');

disp('Enter the Application')
disp('1 = 2D PIV')
disp('2 = Stereo PIV')
app = input(': ');

tic

if app == 1
    namekey = '*.vec';
    files = dir([folData namekey]);
    if isempty(files) == 1
        files = dir([folData '*.VEC']);
    end
else
    namekey = '*.v3d';
    files = dir([folData namekey]);
    if isempty(files) == 1
        files = dir([folData '*.V3D']);
    end
end
L = length(files);
L=10;

for i=1:L
    if i==1
        vecfile = [folData files(i).name];
        [nc,I,J,~,~,X,Y,Z,Ui,Vi,Wi,CHCi] = matrix(vecfile);
        U = zeros(J,I,L);
        V = zeros(J,I,L);
        W = zeros(J,I,L);
        CHC = zeros(J,I,L);
        U(:,:,i) = Ui;
        V(:,:,i) = Vi;
        W(:,:,i) = Wi;
        CHC(:,:,i) = CHCi;
    else
        vecfile = [folData files(i).name];
        [~,~,~,~,~,~,~,~,Ui,Vi,Wi,CHCi] = matrix(vecfile);
        U(:,:,i) = Ui;
        V(:,:,i) = Vi;
        W(:,:,i) = Wi;
        CHC(:,:,i) = CHCi;
    end
    
end

save([folData 'stackedVecFiles.mat'],'X','Y','Z','U','V','W','CHC')

toc